<template>
    <span>
        <span style="color:#444;margin-right: 5px;line-height:32px;">告警类型测试</span>
        <Button size="small" @click="handleTestAlarmTemplate('maxtime')" style="margin-right: 5px;">maxtime</Button>
        <Button size="small" @click="handleTestAlarmTemplate('maxcount')" style="margin-right: 5px;">maxcount</Button>
        <Button size="small" @click="handleTestAlarmTemplate('test')" style="margin-right: 5px;">test</Button>
        <span>为空则使用默认模板</span>
    </span>
</template>

<script>
export default {
    name: "AlarmTemplateTestButton",
    props: {
        alarm_plan: Object
    },
    data() {
        return {
            alarm_plan_current: {}
        }
    },
    methods: {
        handleTestAlarmTemplate(alarm_type) {
            this.alarm_plan_current.plan_begintime = this.alarm_plan.plan_time[0];
            this.alarm_plan_current.plan_endtime = this.alarm_plan.plan_time[1];
            this.alarm_plan_current.alarm_type = alarm_type;
            this.alarm_plan_current.plan_template = this.alarm_plan.plan_template;
            this.alarm_plan_current.plan_id = this.alarm_plan.plan_id;
            this.alarm_plan_current.plan_name = this.alarm_plan.plan_name;
            this.alarm_plan_current.plan_maxtime = this.alarm_plan.plan_maxtime;
            this.alarm_plan_current.plan_maxcount = this.alarm_plan.plan_maxcount;
            this.alarm_plan_current.plan_rangetime = this.alarm_plan.plan_rangetime;
            this.$http.post('/test_alarm_template', this.alarm_plan_current).then(res => {
                if (res.status === 'ok') {
                    this.$Notice.warning({
                        title: '测试告警模板',
                        desc: res.data,
                        duration: 10
                    });
                }else {
                    this.errorMessage(res.data);
                }
            }).catch(err => {
                this.errorMessage(err);
            });
        },
    }

}
</script>